﻿using System;
using System.Linq.Expressions;
using System.Web.Mvc;

namespace Company.Web.Infrastructure
{


    public static class UrlHelperExtension
    {

        public static string Stylesheet(this UrlHelper helper, string filename)
        {
            string target = helper.Content(String.Format("~/Content/css/{0}", filename));
            return String.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\" media=\"screen\" />", target);
        }

        public static string Script(this UrlHelper helper, string filename)
        {
            string target = helper.Content(String.Format("~/Scripts/{0}", filename));
            return String.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", target);
        }

        public static string SubmitButton(this UrlHelper helper, string htmlText, string htmlId, string action, string controller)
        {
            string routes = helper.Action(action, controller);
            string TagJquery = "<script type=\"text/javascript\">$(function() {$('#" + htmlId + "').click(function() {$(\"form\").attr(\"action\", '" + routes + "');});});</script>";
            string TagButton = String.Format("<button id=\"{1}\" type=\"submit\" class=\"button\">{0}</button>", htmlText, htmlId);
            return TagButton + TagJquery;
        }

        public static string Submit(this UrlHelper helper, string htmlText, string htmlId)
        {
            string TagButton = String.Format("<button id=\"{1}\" type=\"submit\" class=\"button\">{0}</button>", htmlText, htmlId);
            return TagButton;
        }

        public static string HrefButton(this UrlHelper helper, string htmlText, string action, string controller, string parameters)
        {
            string routes = helper.Action(action, controller) + "?" + parameters;
            string TagButton = String.Format("<a href={1} style=\"text-decoration:none\"><div class=\"button\">{0}</div></a>", htmlText,routes);
            return TagButton;
        }

        public static string HrefButton(this UrlHelper helper, string htmlText, string action, string controller)
        {
            string routes = helper.Action(action, controller);
            string TagButton = String.Format("<a href=\"{1}\" style=\"text-decoration:none\"><div class=\"button\">{0}</div></a>", htmlText, routes);
            //string TagButton = String.Format("<div class=\"button\"><a href=\"{1}\" style=\"text-decoration:none\">{0}</a></div>", htmlText, routes);
            return TagButton;
        }
    }
}